<template>
  <!-- hidden PageHeaderWrapper title demo -->
  <page-header-wrapper :title="false" >
    <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
      <a-form @submit="handleSubmit" :form="form">
        <a-form-item
          label="入库店面"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-select v-decorator="['storeId']" placeholder="请选择" >
            <a-select-option :value="i.id" v-for="i in this.storeOption" :key="i.value">{{ i.storeName }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="供应商"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-select v-decorator="['supplyId']" placeholder="请选择供应商" >
            <a-select-option :value="i.id" v-for="i in this.suppliesOption" :key="i.value">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :wrapperCol="{ span: 24 }"
          style="text-align: center"
        >
          <a-button htmlType="submit" type="primary" icon="check">下一步</a-button>
          <!-- <a-button style="margin-left: 8px">{{ $t('form.basic-form.form.save') }}</a-button> -->
        </a-form-item>
      </a-form>
    </a-card>
  </page-header-wrapper>
</template>
  
<script>
import { getStoreListUsingPOST } from '@/api/api/mendianguanli.ts'
import { getSuppliesListUsingPOST, } from '@/api/api/jingxiaoshangyunyingshangguanli.ts'
  export default {
    name: 'ReturnFactoryOutStoreIndex',
    data () {
      return {
        form: this.$form.createForm(this),  
        queryParam: {
          pageNo:1,
          pageSize:999,
          queryCondition:'',
          status:1
        },
        suppliesOption: [],
        storeOption: []
      }
    },
    created () {
      this.handleStore()
      this.handleSupplies()
  },
    methods: {
      // handler
      handleSupplies(){
        getSuppliesListUsingPOST(this.queryParam).then((res) => {
          this.suppliesOption = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
      },
      handleStore(){
        getStoreListUsingPOST(this.queryParam).then((res) => {
          this.storeOption = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
      },
      handleSubmit (e) {
        e.preventDefault()
        this.form.validateFields((err, values) => {
          if (!err) {
            if(!values.storeId){
              this.$message.warn('请选择入库店面')
            }else if(!values.supplyId){
              this.$message.warn('请选择供应商')
            }else{
              this.$router.push({ name: `ReturnFactoryInStoreDetail` , params: {storeId: values.storeId,supplyId:values.supplyId} })  
            }
          }
        })
      }
    }
  }
</script>